<template>
  <div class="content">
    <div style="margin-top: 5rem;">
      <h3>{{ $route.meta.title }}</h3>
      <el-divider />

    </div>
    <div>
      <div class="box">
        <div class="boxtitle">
          当前BOK 转出手续费
        </div>
        <div class="boxcontent">
          <div class="int" style="width: 40%;"> <el-input v-model="params.value" type="text" @input="zhuzhuxia" /></div> %
          &nbsp; &nbsp; &nbsp; &nbsp;
          <el-button type="primary" @click="determine">确定</el-button>
        </div>
      </div>

    </div>
  </div>
</template>
<script>
import { getRolloffCommissionConf, rolloffCommissionConf } from '@/api/jackbo/platform.js'
export default {
  name: 'Nodeamount',
  data() {
    return {
      params: {
        value: ''
      }
    }
  },
  mounted() {
    this.getlist()
  },
  methods: {
    getBit(value, bit = 3) {
      let str = value.toString()
      const strIndex = str.indexOf('.')
      if (strIndex === -1) return str
      str = str.substring(0, strIndex + bit)
      console.log(str, bit)
      return str
    },
    zhuzhuxia(e) {
      let price = this.params.value
      const that = this
      price = price.replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
      price = price.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
      price = price.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      price = price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')// 只能输入两个小数
      if (price.indexOf('.') < 0 && price != '') { // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        price = parseFloat(price)
      }
      if (price >= 99) {
        price = 99
      }
      if (price < 0) {
        price = 0
      }
      that.params.value = price
      // console.log(price)
    },
    async getlist() {
      const res = await getRolloffCommissionConf()
      if (res.code == 0) {
        for (const key in res.data) {
          res.data[key] = this.getBit(res.data[key])
        }
        console.log(res.data)
        this.params = res.data
      }
    },
    async determine() {
      const params = {
        ...this.params
      }
      const res = await rolloffCommissionConf(params)
      if (res.code == 0) {
        this.getlist()
      }

      // console.log(obj)
    }
  }
}
</script>
<style scoped>
  .box{
    /* height:8rem; */
    padding: 1rem;
    border: 1px solid #dddddd;
    border-radius: 0.5rem;
    width: 98%;
    margin: 0 auto;
      /* border; */
      margin-top: 2rem;

  }
  .boxtitle{
    font-size:1.25rem;
    height: 3rem;
    line-height: 3rem;
  }
  .int{
    display: inline-block;
    width: 10rem;

  }
  .boxcontent{
    font-size:1.25rem;
    height: 3rem;
    line-height: 3rem;
  }
</style>
